package io.coderyeah.ymcc.service.impl;

import cn.hutool.core.util.RandomUtil;
import io.coderyeah.ymcc.constant.RedisConstants;
import io.coderyeah.ymcc.result.JSONResult;
import io.coderyeah.ymcc.service.ITokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author lqs
 * @date 2022/11/1 19:37
 */
@Service
public class TokenServiceImpl implements ITokenService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public String getOrderToken(String ids) {// ids:需要生成订单的课程id
        // 获取登录用户id FIXME
        long loginId = 3L;
        // 生成随机字符串作为token
        String token = RandomUtil.randomString(10);
        // 存入redis
        stringRedisTemplate.opsForValue().set(RedisConstants.ORDER_TOKEN + loginId + ":" + ids, token, RedisConstants.EXPIRE_TIME, TimeUnit.MINUTES);
        return token;
    }
}

